Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

Asp.Net Razor: Query website URL path

06.11.2018 (👁6878)

Asp.Net Razor: Query website

 

How to query in Asp.Net when calling a page where you are?

 

Task:

I would like to call the website page: Edit, that some HTML sections such as advertising are not displayed.

The Asp.Net MVC Core Website Edit is saved as View: Edit.cshtml.

A view is usually embedded in a master layout like this: Views / Shared / _Layout.cshtml.

 

Solution:

You have to query the Context.Request.Path in the view.

This will return the complete path at runtime like: "/ Notes / Edit"

You can then control the output of HTML as in the example with the @ {Razor} from Server-Script

@{

    //----< Ads >----

    string sWebsite = Context.Request.Path;

 

    sWebsite = sWebsite.ToLower();

    if (sWebsite.Contains("/edit") == false)

    {

        await Html.PartialAsync("_Ads_Google_Automatic");

    }

    //----</ Ads >----

}

 

 

 

Name

Value

Type

Context.Request

{Microsoft.AspNetCore.Http.Internal.DefaultHttpRequest}

Microsoft.AspNetCore.Http.HttpRequest {Microsoft.AspNetCore.Http.Internal.DefaultHttpRequest}

sWebsite.Contains("/edit")

true

bool

sWebsite

"/notes/edit"

string

sWebsite.IndexOf("/edit")

6

int

Context.Request.Path

{/Notes/Edit}

Microsoft.AspNetCore.Http.PathString

sWebsite.Contains("/Edit")

false

bool