Tuesday, November 19, 2019

Use regexp to filter for question mark (?) parameter in url and add either ? or &

1.
var searchString = action + ((action.indexOf('?') == -1) ? '?search=' : '&search=');

2.
var startChar = action.indexOf('?') == -1 ? '?' : '&',
    searchString = action +  startChar  + 'search=' + search + '&filter=';

3.
var hasQM = (/\?/).test(action);
var searchString = action + (!hasQM ? '?' : '&') + 'search=' + search + '&filter='

Monday, November 18, 2019

A potentially dangerous Request.Path value was detected from the client (*)

If you're using .NET 4.0 you should be able to allow these urls via the web.config

<system.web>
    <httpRuntime
            requestPathInvalidCharacters="&lt;,&gt;,%,&amp;,:,\,?" />
</system.web>
Note, I've just removed the asterisk (*), the original default string is:

<httpRuntime
          requestPathInvalidCharacters="&lt;,&gt;,*,%,&amp;,:,\,?" />

Monday, November 11, 2019

Can we pass parameters to a view in SQL?

A possible solution would be to implement a stored function, like:

CREATE FUNCTION v_student (@pintSno INT)
RETURNS TABLE
AS
RETURN
   SELECT * FROM Student WHERE stu_id=@pintSno ;


This allows you to use it as a normal view, with:

SELECT * FROM v_student (3)

Thursday, November 7, 2019

Split string and take last element In sql

DECLARE @full_path VARCHAR(1000)
SET @full_path = '\\SERVER\D$\EXPORTFILES\EXPORT001.csv'


SELECT SUBSTRING( @full_path , LEN(@full_path) -  CHARINDEX('\',REVERSE(@full_path)) + 2  , LEN(@full_path)  )


Result :
EXPORT001.csv


Syntax

 select url,
(CASE WHEN CHARINDEX('/', url, 1)=0 THEN url ELSE RIGHT(url, CHARINDEX('/', REVERSE(url)) - 1) END) AS ResultValue
from(
    select 'Articles/Search/ArtMID/2681/ArticleID/2218/Diet.aspx' as url union
    select 'OurStory/MD.aspx' as url union
    select 'AMD.aspx' as url
)dummytablename

Result value :



Tuesday, November 5, 2019

How to Set Master Page dynamically?

void Page_PreInit(Object sender, EventArgs e)
{
    this.MasterPageFile = "~/MyMaster.master";
}

Explanation: 
You can attach a master page dynamically to a content page. Because the master page and content page are merged during the initialization stage of page processing, a master page must be assigned before then. Typically, you assign a master page dynamically during the PreInit stage.

Mixed Content: The page at xxx was loaded over HTTPS, but requested an insecure

 Mixed Content: The page at ' https ://www.test.com/signup.aspx' was loaded over HTTPS, but requested an insecure script ' http ...