Jump to content

How To Get Base Url In Mvc


Recommended Posts

Posted

how to get base url and use it as string parameter  in mvc ? 

I want to determine url between development and production server 

 

ila undi code 

 

 public ActionResult RedirectToLogin(string URL)

        {

String redirectURL = "http://www.afdb.com/pages/login.aspx?ReturnUrl=" + URL;

            Response.Redirect(redirectURL);

            return null;

        }

 

 

www.afdb.com  degara it should determine which server user is on and send that url  string parameter pass chesthu cheycha?   {0} 

 

 

something like 

 

redirectURL = string.Format(@"{0}/pages/login.aspx?ReturnUrl=", baseURL);  

 

Posted

Enti bhayya afdb ni emanna hack chese pani lo unnava??
Unte matram hightlite vishayam db lone doubt adagadam

...

Posted
 public static String GetPreviousUrl()
        {
            var serverVars = System.Web.HttpContext.Current.Request.ServerVariables;
            var url = (!String.IsNullOrEmpty(serverVars["HTTP_REFERER"])) ? serverVars["HTTP_REFERER"] : String.Empty;
 
            return url;
        }
 
method create chesukuni baseurl = GetPreviousUrl() method ki call cheyyi
Posted

 

 public static String GetPreviousUrl()
        {
            var serverVars = System.Web.HttpContext.Current.Request.ServerVariables;
            var url = (!String.IsNullOrEmpty(serverVars["HTTP_REFERER"])) ? serverVars["HTTP_REFERER"] : String.Empty;
 
            return url;
        }
 
method create chesukuni baseurl = GetPreviousUrl() method ki call cheyyi

 

 

how to call the method  ? 

sorry I am just learning all this.  

 

and  ikada situation 

for example  my website is  www.afdb.com   andulo oka link click chesthe ( for suppose  www.mydb.com) it goes to login page for afdb.com  which is above url  "http://www.afdb.com/pages/login.aspx?"  so ee redirection  avali  according to server environment. 

 

 

 

 

konni examples tho ila rasanu 

 

 

        public ActionResult RedirectToLogin(string URL)

        {

string redirectURL = "";

string helpURL = "";

string webbaseURL = "";

 

var request = System.Web.HttpContext.Current.Request;

 

try

{

if (request.Url.PathAndQuery.Contains("?"))

helpURL = string.Format("{0}{1}", webbaseURL, request.Url.PathAndQuery.Split('?')[0]);

else

helpURL = request.Url.ToString(); 

}

catch

{

helpURL = "%3F"

}

 

redirectURL = string.Format(@"{0}/pages/login.aspx?ReturnUrl={1}", webbaseURL, returnURL);

            Response.Redirect(redirectURL);

            return null;

 

 

but ipudu emo it is going to http://www.mydb.com/pages/login.aspx?

instead it should pass http://www.devafdb.com/pages/login.aspx? or  http://www.prodafdb.com/pages/login.aspx?

Posted

how to call the method  ? 

sorry I am just learning all this.  

 

and  ikada situation 

for example  my website is  www.afdb.com   andulo oka link click chesthe ( for suppose  www.mydb.com) it goes to login page for afdb.com  which is above url  "http://www.afdb.com/pages/login.aspx?"  so ee redirection  avali  according to server environment. 

 

 

 

 

konni examples tho ila rasanu 

 

 

        public ActionResult RedirectToLogin(string URL)

        {

string redirectURL = "";

string helpURL = "";

string webbaseURL = "";

 

var request = System.Web.HttpContext.Current.Request; change to   --- var request = System.Web.HttpContext.Current.Request.ServerVariables;

 

 

try

{

if (request.Url.PathAndQuery.Contains("?"))

helpURL = string.Format("{0}{1}", webbaseURL, request.Url.PathAndQuery.Split('?')[0]);

else

helpURL = request.Url.ToString(); 

}

catch

{

helpURL = "%3F"

}

 

redirectURL = string.Format(@"{0}/pages/login.aspx?ReturnUrl={1}", webbaseURL, returnURL);

            Response.Redirect(redirectURL);

            return null;

 

 

but ipudu emo it is going to http://www.mydb.com/pages/login.aspx?

instead it should pass http://www.devafdb.com/pages/login.aspx? or  http://www.prodafdb.com/pages/login.aspx?

 

Posted

Django lo ilantidi Edo chusa ninna.... Ikkada emo verey language lo undi bye1

×
×
  • Create New...