2014年7月13日 星期日

[RESOLVED] Automatically direct the site


Hi,

For instance, I start the web site like

http://mycomp.com:81/Start



where Start is one starting project. How to make it automatically direct that to



http://mycomp.com:81/Start



once the user has located to



http://mycomp.com



?





Hi wmec,


i think you can use, Response.Redirect() method in your detault page, that can direct you to your resired location, for example,


// in default.aspx
void Page_Load()
{
Response.Redirect("~/Start/yourPage.aspx");
}

Thanks,



Hi,


You can make the default page setting in IIS level.


there might be other ways to do thi. You can check this post http://forums.asp.net/t/1196778.aspx?Cannot+get+default+page+with+navigating+to+URL+



If your server is running IIS7, you should be able to set the start page for your site in your web.config file




















hi ,


 


if you want to be redirected to the http://mycomp.com:81/Start , and keep the
http://mycomp.com  you can either use the response.redirect in your aspx.c# page and ifyou want to keep the address as it is and still being redirected , you can use the server.transfer ( as long as you are still in the same
domain)


 


one more thing you can also use javascript as well to do it :



or even in the html :



 


 


 



I suspect your actual question is how do you get your website running on the default port.  For your site to be accessable via
http://mycomp.com then it has to be running on port 80, if it isn't you can't access it via that url.  However to answer your question, put this in your global.asax file


protected void Session_Start(object sender, EventArgs e)
{
int port = Request.Url.Port;
if (port != 80)
{
string url = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Host, Request.Url.AbsolutePath);
Response.Redirect(url, false);
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
}





Ramesh Ram



If your server is running IIS7, you should be able to set the start page for your site in your web.config file




















Thanks all.


Ramesh,


Yes, I am using IIS 7.5.


Do you mean to put the above into Web.config file of the startup project? Then how does the server know this, when the user has selected this to go?


http://mycomp.com



If you put my above code way in your webconfig , The default document page is load  whenever your application load first time. 





wmec



Ramesh Ram

If your server is running IIS7, you should be able to set the start page for your site in your web.config file



















Thanks all.


Ramesh,


Yes, I am using IIS 7.5.


Do you mean to put the above into Web.config file of the startup project? Then how does the server know this, when the user has selected this to go?





did you deploy the webconfig file in server ? if yes , then the server was automatically load this page  in first time by whenever run your application  . and anywhere we can load the page at second , third etc time .



Thanks.


The startup project has one Web.config file inside. Are you talking about the other Web.config file in the server? Do you know the relevant place of that?





wmec



Thanks.


The startup project has one Web.config file inside. Are you talking about the other Web.config file in the server? Do you know the relevant place of that?





I don't think people have completely grasped your problem.  Changing the default document is not going to help you.  Implement my code in the global.asax file.


Edit: Didn't realise you want the re-direction to work the other way


protected void Session_Start(object sender, EventArgs e)
{
int port = Request.Url.Port;
if (port == 80)
{
string url = string.Format("{0}://{1}:81{2}", Request.Url.Scheme, Request.Url.Host, Request.Url.AbsolutePath);
Response.Redirect(url, false);
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
}

However my point still stands, I don't think this is going to answer your actual problem.  If your site isn't running on port 80 then you can't kick any code off to influence what happens when someone directs to your site.  Sites run on specific ports, not
on servers, and mycomp.com is simply shorthand for mycomp.com:80 and if your site is on mycomp.com:81 then accessing mycomp,.com isn't going to hit your code.



Many thanks Aidy.


Do you think I have to change the port from 81 to 80, and then after applying your codes in Global.asax, it should work?



If your site running on both ports, then yes it would work.  Or else whatever *is* running on port 80 should have the code added to its global.asax


沒有留言:

張貼留言