2016-05-19 64 views
0

我有一個驗證站點,它接收來自多個站點(站點1,2,3)的請求以驗證用戶。在MVC 6中,URL重寫

EXP:

1.網站/位點1 /控制器/動作

2.網站/位點2 /控制器/動作

3.網站/位點3 /控制器/動作

我想顯示上述的URL作爲

網站/自定義文本/控制器/動作

我需要更換現場1,現場2,現場3自定義文本

和執行的操作...

在此請幫助.....

問候 P

回答

0
Yes can can do it by some simple steps 
    1.)Add the custom MapRoute in Startup.cs file in app.UseMvc section like this :- 



    app.UseMvc(routes => 
       { 
        routes.MapRoute(
         name: "team", 
         template: "Site/{DiffrentSiteName}/{controller}/{action}/{id?}", 
         defaults: new { controller = "DefaultcontrollerName ", action = "Index" } 
       }); 

    2.)Then in the default control index method get that site name like this 



     public IActionResult Index(string DiffrentSiteName) 
       { 
        var siteName = DiffrentSiteName; 
        return view(); 
       } 
    3.)We have to use the same name to get the value of site from the url 
in controller like we have used above (DiffrentSiteName in url and in 
index method) 


    4.) So the url will be like : 
    1.)http:Site/Site1name/controller/action/parm 
    2.)http:Site/Site2name/controller/action/parm 
    3.)http:Site/Site3name/controller/action/parm 


    5.)So when you get the name of the Site in the index 
method you can respond accordingly or according to the 
site name