Freelance Project Requests info@CodeDocu.de Software Development in C# WPF Asp.Net Core Vba Excel Word SQL-Server EF Linq, UWP Net
#

 

 

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

 

Mobile
»
Asp.Net Razor: Query website URL Path

.

Contact for Jobs, Project Requests: raimund.popp@microsoft-programmierer.de