sribha
sribha
BOMMI
51 posts
Don't wanna be here? Send us removal request.
sribha · 2 years ago
Text
Powershell script for Finding .Net Framework Version skimming through .*proj files
https://www.codeproject.com/Questions/1184052/How-to-find-NET-version-of-all-projects-in-solutio
Improvised code from above source
$solutionFolder= [Path of the solution]
$ReportOutput= "C:\WebApplications-Report.csv"
$listapp=@()
Get-ChildItem $solutionFolder -Include *.*proj -Recurse -Force | ForEach-Object {
[xml]$projectXml = (Get-Content ($_))
$namespace=New-Object System.Xml.XmlNamespaceManager($projectXml.NameTable)
$namespace.AddNamespace("nsp", $projectXml.DocumentElement.NamespaceURI)
$dotnetVersionNode = $projectXml.SelectSingleNode("//nsp:TargetFrameworkVersion", $namespace)
if ($dotnetVersionNode -eq $null) {
$dotnetVersionNode = $projectXml.SelectSingleNode("//nsp:TargetFramework", $namespace)
}
   $objapp= $dotnetVersionNode.InnerXml
   $listapp += $objapp +";"
#Write-Host $_ : $dotnetVersionNode.InnerXml -f Green
   Write-Host $_ : $objapp -f Green
   #Write-Host $_ : $listapp -f Red
}
#$listapp | Export-csv $ReportOutput -notypeinformation
0 notes
sribha · 2 years ago
Text
Powershell script to get list of IIS site info in excel format
#Read more:  https://www.sharepointdiary.com/2016/01/get-all-web-applications-in-sharepoint-using-powershell.html#ixzz7tJxgLy48
From <https://www.sharepointdiary.com/2016/01/get-all-web-applications-in-sharepoint-using-powershell.html>
Code improvised from above sources
try{
Import-Module WebAdministration
# Get-WebApplication
#Get-WebApplication |Get-Member
#$WebAppNames = Get-WebApplication  |Select @{Name='Name';Expression={$_.Path.Trim('/')}} |Select -Expand Name
# $webapps = Get-WebApplication -site "www.esa.dced.state.pa.us"
$webapps = Get-WebApplication
$list = @()
$listapp =@()
$ReportOutput= "C:\WebApplications-Report.csv"
foreach ($webapp in $webapps)
{
$itemapp=@{}
$itemapp.Name=$webapp |Select @{Name='Name';Expression={$_.Path.Trim('/')}} |Select -Expand Name
#$itemapp.Name=$webapp.Name
$itemapp.AppPool=$webapp.applicationPool
$itemapp.PhysicalPath=$webapp.PhysicalPath
# $itemapp.ItemXPath=$webapp.itemXPath
get
$objapp = New-Object PSObject -Property $itemapp
   $listapp += $objapp
}
# $listapp | Format-Table -a -Property "Name"
# $listapp | Format-Table -a -Property  "AppPool"
# $listapp | Format-Table -a -Property  "PhysicalPath"
$listapp | Export-csv $ReportOutput -notypeinformation
Write-Host "Web Application Audit Report has been Generated!" -f Green
}catch
{
$ExceptionMessage = "Error in Line: " + $_.Exception.Line + ". " + $_.Exception.GetType().FullName + ": " + $_.Exception.Message + " Stacktrace: " + $_.Exception.StackTrace
$ExceptionMessage
}
# Powershell.exe -File "C:\GetApps.ps1"
0 notes
sribha · 8 years ago
Text
web.config setting to pass session in url for each request to the server instead of storing it in memory
<sessionState mode="InProc" timeout="30" cookieless="true" />
0 notes
sribha · 8 years ago
Text
 still if it does not work then make sure the target farmework is same on all apps
 <httpRuntime  targetFramework="4.5.2" />
web.config entry to have same decryption logic on multiple servers/applications
Make sure the below values are same on all servers and applications web.config
<machineKey validationKey=“xxx”                decryptionKey=“xxx”                validation=“SHA1” decryption=“AES” />
1 note · View note
sribha · 8 years ago
Text
web.config entry to have same decryption logic on multiple servers/applications
Make sure the below values are same on all servers and applications web.config
<machineKey validationKey="xxx"                decryptionKey="xxx"                validation="SHA1" decryption="AES" />
1 note · View note
sribha · 8 years ago
Text
Custom HTTP Module to implement checks against the resources that were being requested
Add this in web.config
In system.webServer. handlers section
<modules>      <add name="LoginDotNetModule" type="LoginDotNetModule" />    </modules>
Public Class LoginDotNetModule    Implements IHttpModule    Public Sub Init(context As HttpApplication) Implements IHttpModule.Init
       '_httpApp.AddOnAuthenticateRequestAsync(AddressOf OnBeginAuthentication, AddressOf OnEndAuthentication)
       AddHandler context.AuthenticateRequest, AddressOf CustomAuthentication        'AddHandler context.Error, AddressOf HandleError    End Sub
   Private Sub CustomAuthentication(sender As Object, e As EventArgs)        ‘ write logic here    End Sub   
   Public Sub Dispose() Implements IHttpModule.Dispose    End Sub     
End Class
Public Class LoginDotNetPrincipal    Implements IPrincipal
   Private _identity As IIdentity    Private _formsIdentity As FormsIdentity    Public Sub New(ByVal formsIdentity As FormsIdentity)        _identity = formsIdentity        _formsIdentity = formsIdentity    End Sub    Public ReadOnly Property Identity As IIdentity Implements IPrincipal.Identity        Get            Return _identity        End Get    End Property
   Public Function IsInRole(role As String) As Boolean Implements IPrincipal.IsInRole        Return Nothing    End Function    Public ReadOnly Property FormsIdentity As FormsIdentity        Get            Return _formsIdentity        End Get    End Property
End Class
0 notes
sribha · 8 years ago
Text
Custom ConfigurationManager Class that is used to change the appsettings values runtime
Imports Microsoft.VisualBasic Imports System Imports System.Collections.Specialized Imports System.Configuration Imports System.Configuration.Internal Imports System.Reflection Public NotInheritable Class clsCustomConfigurationManager    Implements IInternalConfigSystem    Private ReadOnly baseconf As IInternalConfigSystem    Private appsettings As Object    Public Sub New(ByVal baseconf As IInternalConfigSystem)        Me.baseconf = baseconf
   End Sub    Public ReadOnly Property SupportsUserConfig As Boolean Implements IInternalConfigSystem.SupportsUserConfig        Get            Return baseconf.SupportsUserConfig        End Get    End Property
   Public Sub RefreshConfig(sectionName As String) Implements IInternalConfigSystem.RefreshConfig        If (sectionName = "appSettings") Then appsettings = Nothing        baseconf.RefreshConfig(sectionName)    End Sub
   Public Function GetSection(configKey As String) As Object Implements IInternalConfigSystem.GetSection        If configKey = "appSettings" AndAlso Me.appsettings IsNot Nothing Then Return Me.appsettings        Dim o As Object = baseconf.GetSection(configKey)        If (configKey = "appSettings" AndAlso TypeOf o Is NameValueCollection) Then            ' create a New collection because the underlying collection Is read-only            Dim cfg = New NameValueCollection(DirectCast(o, NameValueCollection))
          ' add Or replace your settings
           cfg("test") = "Hello world"            Me.appsettings = DirectCast(cfg, Object)            o = Me.appsettings        End If        Return o    End Function End Class
Call this method in first before changing the values.
   private sub setupcustomconfig()        'initialize the configurationmanager        dim o as object = configurationmanager.appsettings        'hack your proxy iinternalconfigsystem into the configurationmanager        dim s_configsystem as system.reflection.fieldinfo = gettype(configurationmanager).getfield("s_configsystem", system.reflection.bindingflags.[static] or system.reflection.bindingflags.nonpublic)        s_configsystem.setvalue(nothing, new clscustomconfigurationmanager(directcast(s_configsystem.getvalue(nothing), system.configuration.internal.iinternalconfigsystem)))    end sub
0 notes
sribha · 8 years ago
Text
Changing ConnectionString Values at runtime without refreshing the app using reflection
ConnectionStringSettings o  = ConfigurationManager.ConnectionStrings[0];
               System.Reflection.FieldInfo s_configSystem = typeof(ConfigurationElement).GetField("_bReadOnly", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
               s_configSystem.SetValue(o, false);
o.ConnectionString = “somevalue”;
0 notes
sribha · 8 years ago
Text
Passing MVC model to jquery ajax post
Put this in some .js file
function PostToController(url, inputData,scbfn ) {
$.ajax({    url: url,    type: 'POST',    data: inputData,    dataType:'json',    contentType: 'application/json; charset=utf-8',    success: function (data) {        alert("success");        scbfn(data);    },    error: function () {        alert("error");    } }); }
java script in your view
<script>    $(document).ready(function() {
       var submitButtonId;        $('input[type=submit]').click(function(event) {            submitButtonId = event.target.id;            //alert(submitButtonId);        });
       $('form').submit(function(event) {
           //alert('inside template button clicked');            //alert(document.activeElement);            //alert(document.activeElement.getAttribute('id'));            //var btn = $(this).find("input[type=submit]:focus");
           //if (btn[0].id === 'btnCreateTemplate') {            //    alert('create template button clicked');            //}
           //if (btn[0].id === 'btnAddQuestion') {            //    alert('Add question button clicked');            //}
           //var model = $('form').serialize();            //alert(model);
           //var myModel = JSON.stringify(model);            //alert(myModel);
           //var modelArray = $('form').serializeArray();            //alert(modelArray);
           var newTemplate = {                TemplateName: $('#NewTemplate_TemplateName').val()            };
           var formModel = {                NewTemplate: newTemplate,                TemplateQuestions: [],                NewQuestion: []
           };            var jsonModel = JSON.stringify(formModel);            alert(jsonModel);            if (submitButtonId === 'btnCreateTemplate') {                PostToController('/Template/CreateNewTemplate', jsonModel, RefreshTemplateDropdown);                event.preventDefault();            }
           //if (submitButtonId === 'btnAddQuestion') {            //    PostToController('/Template/AddNewQuestion', jsonModel);            //}
       });    });
   function RefreshTemplateDropdown(data) {        var select = $('#NewQuestion_Template_TemplateKey');            select.empty();            //if (addEmpty) {            //    select.append($('<option/>', {            //        value: " ",            //        text: " "            //    }));            //}            $.each(data, function (index, itemData) {                select.append($('<option/>', {                    value: itemData.Value,                    text: itemData.Text                }));            });    } </script>
Models:
public class TemplateQuestionsViewModel    {        public TemplateQuestionsViewModel()        {            NewTemplate=new TemplateViewModel();            TemplateQuestions=new List<QuestionsViewModel>();            NewQuestion=new QuestionsViewModel();        }        public TemplateViewModel NewTemplate { get; set; }        public List<QuestionsViewModel> TemplateQuestions { get; set; }        public QuestionsViewModel NewQuestion { get; set; }
   }
public TemplateViewModel()        {            TemplateQuestions=new List<QuestionsViewModel>();            TemplateTypes=new List<SelectListItem>();        }
       public string TemplateName { get; set; }        public Guid TemplateKey { get; set; }        public List<QuestionsViewModel> TemplateQuestions { get; set; }        public List<SelectListItem> TemplateTypes { get; set; }
       public Guid SelectedTemplateType { get; set; }
0 notes
sribha · 8 years ago
Text
If browser not recording web performance test using visual studio enterprise 2015
If this does not happen you will need to open the Manage-add ons in Internet Explorer and enable the recorder.
Tumblr media
https://blogs.msdn.microsoft.com/charles_sterling/2015/06/01/load-test-series-part-i-creating-web-performance-tests-for-a-load-test/
0 notes
sribha · 8 years ago
Text
SQLServer: Using Sqlcmd utility to run t-sql statements
https://msdn.microsoft.com/en-us/library/ms180944.aspx to run in command prompt: sqlcmd -S <Instance Name> -i <script file with path> -o <output filename with path> to execute sps on multiple instances: :CONNECT <server>\,<instance1> EXEC dbo.SomeProcedure GO :CONNECT <server>\,<instance2> EXEC dbo.SomeProcedure GO
0 notes
sribha · 8 years ago
Text
windows .bat file to execute sql scripts using batch file
Executing Scripts in batch from command line arguments.bat
@echo off cls
rem ---- Declare Variables -------------- SETLOCAL ENABLEEXTENSIONS SET varTitle=SomeTitle SET varInstanceName=%1 SET varInputFileName=%2 SET varOutputFileName=%3
rem ---- DEV Instance commands -------------- title %varTitle% cls echo batch started.... echo **** Connected/Running in %varInstanceName% ****
echo !!!! Running %varTitle% Started !!!!
echo InstanceName= %varInstanceName% echo InputFileName= %varInputFileName% echo OutputFileName= %varOutputFileName%
sqlcmd -S %varInstanceName% -i %varInputFileName% -o %varOutputFileName%
echo !!!! Running %varTitle% Ended !!!!
echo batch ended.
Executing Scripts in batch from local variables.bat
@echo off rem ---- Declare Variables --------------
SETLOCAL ENABLEEXTENSIONS
SET varTitle=SomeTitle SET varInstanceName=<instanceName> SET varInputFileName=<inputfilenamewithpath> SET varOutputFileName=<outputfilenamewithpath>
title %varTitle% cls echo batch started.... echo **** Connected/Running in %varInstanceName% ****
echo !!!! Running %varTitle% Started !!!!
echo InstanceName= %varInstanceName% echo InputFileName= %varInputFileName% echo OutputFileName= %varOutputFileName%
sqlcmd -S %varInstanceName% -i %varInputFileName% -o %varOutputFileName%
echo !!!! Running %varTitle% Ended !!!!
echo batch ended.
http://www.makeuseof.com/tag/write-simple-batch-bat-file/
http://steve-jansen.github.io/guides/windows-batch-scripting/part-2-variables.html
0 notes
sribha · 8 years ago
Text
Satellite Assembly/ Al.exe vs resgen.exe
You use Resource File Generator (Resgen.exe) to compile text files or XML (.resx) files that contain resources to binary .resources files. You then use Assembly Linker (Al.exe) to compile .resources files into satellite assemblies. Al.exe creates an assembly from the .resources files that you specify. Satellite assemblies can contain only resources; they cannot contain any executable code. 
The following Al.exe command creates a satellite assembly for the application Example from the German resources file strings.de.resources.
al /target:lib /embed:strings.de.resources /culture:de /out:Example.resources.dll https://msdn.microsoft.com/en-us/library/21a15yht(v=vs.110).aspx
0 notes
sribha · 8 years ago
Text
Session State Modes
https://msdn.microsoft.com/en-us/library/ms178586.aspx
https://www.mindstick.com/Articles/1123/session-management-in-asp-dot-net-mvc
0 notes
sribha · 8 years ago
Text
ASP.Net WEB API Framework is built on following the principles of REST.
REST is the underlying architecture that web api is built on.
HTTP is a protocol that is being used to Communicate with / Consume Web API.
Web API Introduction Links
ASP.NET Web API is a framework that makes it easy to build HTTP services that reach a broad range of clients, including browsers and mobile devices. ASP.NET Web API is an ideal platform for building RESTful applications on the .NET Framework.
HTTP is not just for serving up web pages. It is also a powerful platform for building APIs that expose services and data. HTTP is simple, flexible, and ubiquitous. Almost any platform that you can think of has an HTTP library, so HTTP services can reach a broad range of clients, including browsers, mobile devices, and traditional desktop applications.
ASP.NET Web API is a framework for building web APIs on top of the .NET Framework. In this tutorial, you will use ASP.NET Web API to create a web API that returns a list of products.
https://www.asp.net/web-api
https://www.asp.net/web-api/overview/mobile-clients/calling-web-api-from-a-windows-phone-8-application
https://www.asp.net/web-api/overview/mobile-clients
1 note · View note
sribha · 8 years ago
Text
Web API Introduction Links
ASP.NET Web API is a framework that makes it easy to build HTTP services that reach a broad range of clients, including browsers and mobile devices. ASP.NET Web API is an ideal platform for building RESTful applications on the .NET Framework.
HTTP is not just for serving up web pages. It is also a powerful platform for building APIs that expose services and data. HTTP is simple, flexible, and ubiquitous. Almost any platform that you can think of has an HTTP library, so HTTP services can reach a broad range of clients, including browsers, mobile devices, and traditional desktop applications.
ASP.NET Web API is a framework for building web APIs on top of the .NET Framework. In this tutorial, you will use ASP.NET Web API to create a web API that returns a list of products.
https://www.asp.net/web-api
https://www.asp.net/web-api/overview/mobile-clients/calling-web-api-from-a-windows-phone-8-application
https://www.asp.net/web-api/overview/mobile-clients
1 note · View note
sribha · 8 years ago
Text
Difference between HTTP Verbs PUT and PATCH; GET, POST
This is what it might look like:
POST /user fname=John&lname=Doe&age=25
The server responds:
200 OK Location: /user/123
In the future, you can then retrieve the user information:
GET /user/123
The server responds:
200 OK <fname>John</fname><lname>Doe</lname><age>25</age>
To modify the record (lname and age will remain unchanged):
PATCH/user/123 fname=Johnny
To update the record (and consequently lname and age will be NULL):
PUT /user/123 fname=Johnny
25 
For me this answer captured the essence of the desired answer. Simple and pragmatic. Granted there are lots of other criteria, but the example provided is a great launch pad. – CyberFonic Feb 1 '12 at 22:09
69 
In the last example, @pbreitenbach uses PUT fname=Jonny. This would set lname and age to default values (probably NULL or the empty string, and integer 0), because a PUT overwrites the whole resource with data from the representation provided. This is not what is implied by "update", to do a real update, use the PATCH method as this does not alter fields which are not specified in the representation. – Nicholas Shanks Jan 31 '13 at 9:43 
18 
Nicholas is right. Also, the URI for the first POST creating a user should be called users because /user/1 makes no sense and there should be a listing at /users. The response should be a 201 Created and not just OK in that case. – DanMan Feb 16 '13 at 19:58 
Nicholas and DanMan are right. This answer is succinct but has several flaws. – leslie.zhang Dec 27 '15 at 13:16 
http://stackoverflow.com/questions/671118/what-exactly-is-restful-programming
0 notes