Перезапись URL в ASP.Net - PullRequest
       17

Перезапись URL в ASP.Net

0 голосов
/ 21 августа 2009

Я хочу реализовать перезапись URL таким образом, чтобы пользователь мог получить доступ к веб-сайту с username.domain.com

например.
www.abc.com/login.aspx
Я должен иметь доступ к этому, как
www.username.abc.com/login.aspx

blogspot также является одним из примеров, таких как http://username.blogspot.com/

Плз, подскажите, как мне это сделать.

Спасибо

Ответы [ 3 ]

2 голосов
/ 24 августа 2009

В основном вам нужно использовать такой инструмент, как Managed Fusion URL Rewriter и Reverse Proxy , со следующим правилом.

RewriteCond {HOST}    www\.(.*)\.abc\.com
RewriteRule ^/login.aspx$    /login.aspx?domain=%1
RewriteRule ^/login.aspx?domain=www\.(.*)\.abc\.com$  /login.aspx?user=$1

Таким образом, оно перейдет к вашему внутреннему приложению, как

URL: www.nick.abc.com/login.aspx
Internal URL: www.abc.com/login.aspx?user=nick

То, что вы должны решить, к чему вы не обратились, это то, как вы собираетесь получить имя пользователя и как вы будете обрабатывать их внутренне.

Но на самом деле вам не нужно перезаписывать URL. Вы просто перенаправляете весь трафик DNS на один и тот же IP-адрес, а затем обрабатываете домен в своем приложении, а не управляете им через DNS.

0 голосов
/ 26 февраля 2014

Попробуйте это в веб-конфигурации под system.web

<system.web>
    <urlMappings enabled="true">
      <add url="~/myaccount" mappedUrl="myaccount.aspx"/>
    </urlMappings>

в коде для записи файла

Response.redirect("~/myaccount")`

Это работает 100%

0 голосов
/ 21 августа 2009

Это возможно при установленном ISAPI Rewrite на сервере

Вы должны поместить это в файл httpd.ini на сайте

# Convert http://example.com to http://www.example.com/
RewriteCond Host: ^example.com
RewriteRule (.*) http\://www\.example.com$1 [I,RP]

# Assuming we have limited number of shared folders.
# We will execute them accordingly regardless of the subdomain.
# Example: http://sub1.example.com/img/logo.jpg -> /img/logo.jpg
# Example: http://www.example.com/img/logo.jpg -> /img/logo.jpg
RewriteRule (/css/.*) $1 [I,O,L]
RewriteRule (/js/.*) $1 [I,O,L]
RewriteRule (/img/.*) $1 [I,O,L]

#Redirect all other subdirectories not matching
#to the list above as subdomains
#example: www.example.com\sub1 -> sub1.example.com
RewriteCond Host: www\.example\.com
RewriteRule /(\w*)/(.*) http\://$1\.example\.com$2 [I,RP]

# If the web site starts with www then point the file to the root folder
# If you specifically created a folder /www/ then you can comment out this section.
RewriteCond Host: (?:www\.)example.com
RewriteRule (.*) $1 [I,O,L]

# Any web site starts other than www will be re-mapped to /<subdomain>/
# Example: http://sub1.example.com/default.asp -> /sub1/default.asp
# Note: if the folder does not exists, then the user will get a 404 error automatically.
RewriteCond Host: (.*)\.example.com
RewriteRule (.*) /$1$2 [I,O,L]

#Fix missing slash char on folders
#This has to be at the end because if invalid dir exists,
#we should show 404 first
RewriteCond Host: (.*)
RewriteRule ([^.?]+[^.?/]) http\://$1$2/ [I,RP]

Жизненно важная часть это:

# Any web site starts other than www will be re-mapped to /<subdomain>/
# Example: http://sub1.example.com/default.asp -> /sub1/default.asp
# Note: if the folder does not exists, then the user will get a 404 error automatically.
RewriteCond Host: (.*)\.example.com
RewriteRule (.*) /$1$2 [I,O,L]

Это лучший способ, который я мог найти. Если у вас нет доступа к серверам и у вас не установлен ISAPI, тогда это не для вас.

Вот ссылка на статью http://www.seoconsultants.com/windows/isapi/subdomains/

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...