Click here to Skip to main content
15,904,817 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am new to MVC 4.

I don't know how to redirect to "index.cshtml" from "Global.asax" Page.

i need your help.

Thanks in advance.
Posted
Updated 5-Nov-12 2:42am
v3

Response.Redirect("~/<controllername>");</controllername>

or
Response.Redirect("~/<controllername>/Index");</controllername>


'controllername' being the foldername of your index.cshtml file.



But if you don't know this stuff I can seriusly suggest taking a tutorial on www.asp.net
 
Share this answer
 
v2
Comments
jeyamothi 6-Nov-12 0:08am    
thanks for your reply. I tried this but its not working properly it throws "response is not available in this current context" error.
To start off with, Global.asax isn't a page. It's a global handler for application level events in ASP.net and certain WCF scenarios.

There are a number of ways to redirect:

http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.redirecttoaction%28v=vs.100%29.aspx[^]

http://msdn.microsoft.com/en-us/library/ms524309%28v=vs.90%29.aspx[^]

You wouldn't redirect directly to a view in MVC though. Without seeing more of your code it's difficult, but I've always found using RedirectToAction fits the bill with MVC.
 
Share this answer
 
Comments
jeyamothi 6-Nov-12 0:10am    
thanks buddy,

This RedirectToAction is working from controller page. But i want to redirect from global.asax.cs to index.cshtml page. So, its not working properly. Kindly give me any other better solution.
jim lahey 6-Nov-12 3:40am    
Then at least click on the second link where it's all about Response.Redirect
jeyamothi 6-Nov-12 6:36am    
i tried this buddy, its not resolve my problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900